<?php

namespace App\Service\User;

use App\Exception\ApiException;
use App\Model\User;
use App\Model\UserProfile;
use App\Service\BaseService;

class GetOnlineStatusService extends BaseService
{
    public function handle()
    {
        $userIds=  $this->request->input('user_ids','');

        $userArr = explode(',', $userIds);

        if (empty($userArr)) {
            throw new ApiException('请选择用户');
        }

        $onlineArr = UserProfile::where( 'online',1)->pluck('user_id')->toArray();

        $data = [];
        foreach ($userArr as $one)
        {
            $data[$one] = (int)in_array($one,$onlineArr);
        }

        $signArr = User::where('status',2)->pluck('id')->toArray();

        $signReturn = [];
        foreach ($userArr as $one)
        {
            if (in_array($one,$signArr))
            {
                $signReturn[] = $one;
            }
        }

        return [
            'list' => $data,
            'sign' => $signReturn
        ];
    }
}